home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: help with strcmp
- Date: 3 Apr 1996 15:05:49 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4jup7d$8s5@solutions.solon.com>
- References: <4jpiek$lp6@blaze.cs.jhu.edu> <DpAI6o.2Cq@iquest.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <DpAI6o.2Cq@iquest.net>, Doug Miller <dlmiller@iquest.net> wrote:
- >I don't notice any place where you have allocated storage for fp prior to
- >attempting to transfer data to it.
-
- I don't notice any place where he attempts to transfer data to it.
-
- Could you please check your work a bit more carefully before posting? You're
- obviously not stupid, and you give some very good advice, but you periodically
- miss the point of a question entirely, or get the entire context of a
- statement wrong; I think you're posting a bit faster than you're reading the
- code.
-
- >lasher@hops.cs.jhu.edu (John E. Davis) wrote:
-
- >>handle = fopen(argv[1], "r");
-
- >>while(!feof(handle)) {
-
- This is bad - not only is it using feof() backwards, but handle has not been
- checked in case it didn't get opened. That would cause a core dump right
- here.
-
- Once again: feof() informs you only that the last read failed; it doesn't
- belong before a read.
-
- >> fp = fgets(data, 40, handle);
-
- This does not attempt to transfer data into fp; it assigns fp to point to
- the return of fgets, which could be either data (which is valid) or NULL,
- in which case...
-
- >> if ( strcasecmp(fp, "<action>\n") == 0) /* the coredump is here */
-
- This would make perfect sense if fgets fails. Unfortunately, the original
- poster is testing for EOF before it happens, not after it happens, and would
- not notice a failure here.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-